!{include file='common/header.htm'}
<script src="!{res file='js/jquery_plus/jquery.form.js'}"></script>
<div class="main_content wrap" id="main_content">
	<div class="left_content" id="wiki_edit_content">
		<h1 flexible-nav>创建词条</h1>
		<form id="wiki_form" method="post">
			<div class="form_item margin_item">
				<strong>词条名称：</strong>
				<div><input type="text" name="q" class="text_input"/></div>
			</div>
			<div class="form_item">
				<strong>词条分类：</strong>
				<div>
					!{html_options name="dict_cate" options=$cates}
				</div>
				!{foreach from=$default_indexs item=dis key=i}
				<div class="default_index" id="index_!{$i}">
					!{foreach from=$dis item=ds key=c}
					<label><input type="checkbox" disabled="disabled" name="p[]" value="!{$ds.name}" !{if $ds.selected eq true}checked="checked"!{/if}/> !{$ds.name}</label> 
					!{/foreach}
				</div>
				!{/foreach}
			</div>
			<div class="form_item">
				<strong>标签：</strong>
				<div><input type="text" name="tag" class="text_input"/></div>
				<p>多个标签使用逗号分隔</p>
			</div>
			<!--  
			<h3>
				<strong flexible-nav>目录名称1</strong>
				<input type="text" name="p[0]" class="text_input"/>
			</h3>
			<textarea class="wysiwyg" id="w1" name='content[0]'></textarea>
			-->
			<div class="center opt_div">
				<input type="submit" value="保存" class="submit_btn"/>
			</div>
		</form>
	</div>
	<div class="right_content">
		<div class="add_info box">
			!{w name='article.single' tpl='content' alias='word_add_info'}<br>
			<input type="button" class="button" onclick="add_index();" value="添加目录">
		</div>
	</div>
</div>
<script src="!{res file='js/jquery_plus/jquery.validate.min.js'}"></script>
<script>
	$(function(){
		$('.tabs').tabs();
		$('.submit_btn').button();
		$('.auto_img').auto_img();
		
		$('select[name="dict_cate"]').change(function(){
			var cate = $(this).val();
			select_cate(cate);
		});
		
		var cate = $('select[name="dict_cate"]').val();
		select_cate(cate);
		
		$('#wiki_form').validate({
			'rules' : {
				'q' : {
					required : true,
					remote : {
						url : '/wiki/check_word/',
						type : 'post',
						data : {
							word : function(){
								return $('input[name="word"]').val();
							}
						}
					}
				}
			},
			'messages' : {
				'q' : {
					required : '词条不能为空！',
					remote : '<a href="/wiki/' + $('input[name="q"]').val() + '">' + $('input[name="q"]').val() + '</a>已经存在！'
				}
			}
		});
	});
	
	function select_cate(cate){
		$('.default_index.selected').removeClass('selected').find('input').attr('disabled', 'disabled');
		$('#index_' + cate).addClass('selected').find('input').removeAttr('disabled');
	}
	
	function add_index(){
		var textarea_count = $('.wysiwyg').length + 1;
		var html = '<h3><strong flexible-nav>目录名称' + textarea_count + '</strong>' +
			'<input type="text" name="p['+(textarea_count-1)+']" class="text_input"/></h3>' +
			'<textarea class="wysiwyg" id="w'+textarea_count+'" name="content['+(textarea_count-1)+']"></textarea>';
		$('.opt_div').before(html);
		create_editor('#w' + textarea_count);
		$('.flexible-nav').remove();
		new FlexibleNav(new FlexibleNavMaker('[flexible-nav]').make().prependTo('body') );
	}
</script>
!{include file='common/footer.htm'}